var App = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    countList: [{name: "洗车液可洗车数量", value: 110}, {name: "预洗液可洗车数量", value: 120}],
    list:[],

    showPopup:false,
    b_id:'',
    number:'',
    remark:'',
    issubmitting:false, //提交状态
    type:1,  //1洗车液 2预洗液
    date:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getDataList();
  },
  // 弹窗
  onShowPopup(e){
    let that = this;
    let b_id = ''
    if(that.data.showPopup == false){
      b_id = e.currentTarget.dataset.bid
    }
    that.setData({
      showPopup: !that.data.showPopup,
      number:"",
      type:1,
      date:'',
      remark:"",
      b_id,
      issubmitting:false
    }); 
  },
  //选择日期
  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
   // 类别
  radioChange(e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)
    this.setData({type:e.detail.value})
  },
  //提交
  formSubmit(e){
    let that =  this
    if(that.data.issubmitting) return;//防止重复提交
    // 设置为正在提交状态
    that.setData({issubmitting:true});
    let data =e.detail.value
    let obj = {
      b_id:that.data.b_id,
      num:data.number,
      remark:data.remark,
      type:that.data.type,
      date:that.data.date
    }
    App.request('/Manage/Management/addConsumables',obj,function(e){
        if (e.code == "200") {
          App.showSuccessToast(e.msg, function() {
            that.getDataList()          //刷新
            that.onShowPopup()
          });
        } else{
          // 设置为可以提交的状态
          that.setData({issubmitting:false});
          App.showError(e.msg);
        }
    })
  },
  //获取数据列表
  getDataList(isPage, page){
    let that = this;
    App.request('/Manage/Management/washConsumables',{},function(e){
      wx.stopPullDownRefresh()
      if (e.code == "200") {
        that.setData({list:e.result})
      } 
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.getDataList();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})